package org.xvergabe.forms.poc.pdfgenerator;

import org.xvergabe.forms.poc.events.PdfFieldBoolCellEvent;
import org.xvergabe.xsd.forms.components.x20.Agreement;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

/**
 * Class to write an Agreement Component to a PDF
 * 
 * @author schiller
 * 
 */
public class AgreementPdfWriter implements XmlPdfWriter<Agreement> {

	@Override
	public void writePdfFromXml(Agreement agreement, PdfWriter writer, Document document) {

		PdfPTable table = new PdfPTable(2);
		try {
			table.setWidths(new int[] { 1, 2 });
			table.setWidths(new int[] { 1, 10 });
			PdfPCell cell = new PdfPCell();
			cell.setCellEvent(new PdfFieldBoolCellEvent(agreement.getAgreed()));
			cell.setBorder(1);
			table.addCell(cell);
			table.addCell(agreement.getExplanation().getValue());
			writer.add(table);
			writer.add(new Chunk("\n"));
		} catch (DocumentException e) {
			e.printStackTrace();
		}

	}

}
